//    Copyright (C) Kherty.  All rights reserved.
using System.IO;
using System.Text;
using System.Xml;

namespace OpenLS.Core
{
    static class StringUtilities
    {
        public static string NiceXml(string xml)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                StringBuilder sb = new StringBuilder();
                StringWriter stringWriter = new StringWriter(sb);
                XmlTextWriter w = new XmlTextWriter(stringWriter);
                w.Indentation = 2;
                w.IndentChar = ' ';
                w.Formatting = System.Xml.Formatting.Indented;
                doc.Save(w);
                return sb.ToString().Replace(@"<?xml version=""1.0"" encoding=""utf-16""?>", "");
            }
            catch
            {
                return xml;
            }
        }
    }
}
